package com.jiangjiang.eshop.auth.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiangjiang.eshop.auth.dao.AccountPriorityRelationshipMapper;
import com.jiangjiang.eshop.auth.domain.AccountPriorityRelationshipEntity;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName AccountPriorityRelationshipService
 * @Description TODO
 * @Author jhw
 * @Date 2021/5/8 11:30
 * @Version 1.0
 **/
@Service
public class AccountPriorityRelationShipService extends ServiceImpl<AccountPriorityRelationshipMapper, AccountPriorityRelationshipEntity> {

    /**
     * 根据权限id,获取关联的账户数
     * @param priorityId 权限id
     * @return
     */
    public Integer countByPriorityId(Long priorityId) {
        return this.count(
                Wrappers.<AccountPriorityRelationshipEntity>lambdaQuery()
                .eq(AccountPriorityRelationshipEntity::getPriorityId, priorityId)
        );
    }

    /**
     * 根据用户账户id查询账户和权限关联关系
     * @param accountId 用户账户id
     * @return 查询结果
     */
    public List<AccountPriorityRelationshipEntity> queryPriorityRelationsByAccountId(Long accountId) {
        LambdaQueryWrapper<AccountPriorityRelationshipEntity> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(AccountPriorityRelationshipEntity::getAccountId, accountId);
        return this.list(wrapper);
    }
}
